<?php

include("../../utility/connection.php");
include("../../model/mPembeli.php");
session_start();

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $vIDPembeli = trim(mysql_real_escape_string($_POST["hidUpdateID"]));
    $vTxtUpdate = trim(mysql_real_escape_string($_POST["hidUpdate"]));
    //echo 'id barang: '.$vIDInformasi.', update: '.$vTxtUpdate;
    
    if ($vTxtUpdate == '') {
        // tampilkan pada form
        $getDetilPembeli = fnPembeliById($vIDPembeli);
        $count = mysql_num_rows($getDetilPembeli);
        if ($count == 1) {
            $_SESSION['ubah'] = '1';
            $_SESSION['idBarang'] = $vIDPembeli;
            $detilPembeli = mysql_fetch_array($getDetilPembeli);
            $_SESSION['detilBarang'] = $detilPembeli;
        }
        
    } else if ($vTxtUpdate == '1') {
        //echo "update data pada database";
        unset($_SESSION['ubah']);
        unset($_SESSION['idBarang']);
        unset($_SESSION['detilBarang']);
        
        $Nama = trim(mysql_real_escape_string($_POST["Editbox1"]));
//        echo $Nama;
        $Alamat = trim(mysql_real_escape_string($_POST["Editbox2"]));
//        echo $Alamat;
        $Telp = trim(mysql_real_escape_string($_POST["Editbox3"]));
//        echo $Telp;
        $Email = trim(mysql_real_escape_string($_POST["Editbox4"]));
//        echo $Email;
        $Milist = trim(mysql_real_escape_string($_POST["hidMilist"]));
//        echo $Milist;
        $Login = trim(mysql_real_escape_string($_POST["Editbox5"]));
//        echo $Login;
        $Password = trim(mysql_real_escape_string($_POST["Editbox6"]));
//        echo $Password;
        
        fnUpdatePembeli($vIDPembeli,$Nama,$Alamat,$Telp,$Email,$Milist,$Login,$Password);
    }

    header("location: ../mstPembeli.php");
}
?>
